package com.bootdo.app.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import java.util.List;
import java.util.Map;

/**
  * @auther: Along
  * @description: javaBean 数据转换工具类
  */
public class BeanUtil {

    public static String toJSONString(Object obj){
        return JSON.toJSONString(obj);
    }
    public static Map beanToMap(Object obj){
        return JSON.parseObject(toJSONString(obj),Map.class);
    }
    public static <T>T mapToBean(Map map,Class<T> clazz){
        return JSON.parseObject(toJSONString(map),clazz);
    }
    public static <T>List<T> dataToList(Object data,Class<T> clazz){
        return JSONArray.parseArray(toJSONString(data),clazz);
    }
    public static <T>T dataToBean(Object data,Class<T> clazz){
        return JSON.parseObject(toJSONString(data),clazz);
    }
}
